package com.landian.sell.service;

import com.landian.sell.utils.SellUtils;
import com.landian.sell.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author caojl
 */
@Service
@Slf4j
public class DataService {

    public List<ResultVO> tempList() {
        List<ResultVO> list = new ArrayList<>();
        for (int i=0; i<10; i++){
            list.add(ResultVO.builder().data(i).build());
        }
        return list;
    }

    public JSONObject goodsInfo() {
        JSONObject jsonObject = getJsonObject("goods.txt");
        return jsonObject;
    }

    public JSONObject sellerInfo(String id) {
        JSONObject jsonObject = getJsonObject("seller.txt");
        return jsonObject;
    }

    private JSONObject getJsonObject(String fileName) {
        InputStream inputStream = DataService.class.getClassLoader().getResourceAsStream(fileName);
        String info = SellUtils.txt2String(inputStream);
        return new JSONObject(info);
    }
}
